﻿#ifndef XSCALECHART_H
#define XSCALECHART_H

#include "xscale.h"

class XScaleChartPrivate;
class XScaleChart : public XScale
{
    Q_OBJECT

    Q_PROPERTY(QString scaleChartTitle READ getScaleChartTitle WRITE setScaleChartTitle)
    Q_PROPERTY(QColor scaleChartTitleColor READ getScaleChartTitleColor WRITE setScaleChartTitleColor)
    Q_PROPERTY(bool scaleChartTitleEnable READ getScaleChartTitleEnable WRITE setScaleChartTitleEnable)

    Q_PROPERTY(QColor scaleChartBarBorderColor READ getScaleChartBarBorderColor WRITE setScaleChartBarBorderColor)
    Q_PROPERTY(QColor scaleChartBarBgColor READ getScaleChartBarBgColor WRITE setScaleChartBarBgColor)
    Q_PROPERTY(QColor scaleChartBarColor READ getScaleChartBarColor WRITE setScaleChartBarColor)
    Q_PROPERTY(QColor scaleChartBarWarningColor READ getScaleChartBarWarningColor WRITE setScaleChartBarWarningColor)

    Q_PROPERTY(double warningValue READ getWarningValue WRITE setWarningValue)
    Q_PROPERTY(double currentValue READ getCurrentValue WRITE setCurrentValue)
    Q_PROPERTY(QColor currentValueStringColor READ getCurrentValueStringColor WRITE setCurrentValueStringColor)
    Q_PROPERTY(bool currentValueShowEnable READ getCurrentValueShowEnable WRITE setCurrentValueShowEnable)

public:
    explicit XScaleChart(QWidget *parent = nullptr, Qt::WindowFlags f=Qt::WindowFlags());
    ~XScaleChart();

    /* Property Interface */
    QString getScaleChartTitle() const;
    void setScaleChartTitle(const QString string);

    QColor getScaleChartTitleColor() const;
    void setScaleChartTitleColor(const QColor &color);

    bool getScaleChartTitleEnable() const;
    void setScaleChartTitleEnable(bool);

    QColor getScaleChartBarBgColor() const;
    void setScaleChartBarBgColor(const QColor &color);

    QColor getScaleChartBarBorderColor() const;
    void setScaleChartBarBorderColor(const QColor &color);

    QColor getScaleChartBarColor() const;
    void setScaleChartBarColor(const QColor &color);

    QColor getScaleChartBarWarningColor() const;
    void setScaleChartBarWarningColor(const QColor &color);

    double getWarningValue() const;
    void setWarningValue(double value);

    double getCurrentValue() const;
    void setCurrentValue(double value);

    QColor getCurrentValueStringColor() const;
    void setCurrentValueStringColor(const QColor &color);

    bool getCurrentValueShowEnable() const;
    void setCurrentValueShowEnable(bool);

protected:
    void paintEvent(QPaintEvent *ev) override;
    void drawBar(QPainter *painter);
    void drawTitle(QPainter *painter);
    void drawCurrentValue(QPainter *painter);

private:
    Q_DISABLE_COPY(XScaleChart)
    XScaleChartPrivate *xScalePrivateP = nullptr;

    void getBarParameters(QPointF &topLeftPoint, QPointF &bottomRightPoint, QPointF &warningTopLeftPoint, QPointF &warningBottomRightPoint);
    void getBaseLineParameters() override;
    void getScaleLineLength() override;
};

#endif // XSCALECHART_H
